package com.katze.boot.file.registry;

import com.katze.boot.file.DirectoryEnum;
import com.katze.common.controller.BaseController;
import com.katze.common.env.AppEnvironment;

import java.nio.file.Files;
import java.nio.file.Path;

public abstract class FileController extends BaseController implements FileSystemHandler {

    protected Path dataDir;

    public FileController(FileSystemRegistrationBean fileSystemRegistrationBean, DirectoryEnum directoryEnum) {
        dataDir = AppEnvironment.DATA_DIR.getPath("FileStorage", directoryEnum.directory());
        try {
            if (Files.notExists(dataDir)) {
                Files.createDirectories(dataDir);
            }
            fileSystemRegistrationBean.registration(this, directoryEnum);
        } catch (Throwable e) {
            throw new RuntimeException(dataDir.toString() + "数据目录无法创建", e);
        }
    }
}
